package cn.yunhe.java.controller;


import cn.yunhe.java.dto.AppDTO;
import cn.yunhe.java.service.AppService;
import cn.yunhe.java.service.IMerchantService;
import cn.yunhe.java.util.SecurityUtil;
import com.huiminpay.transaction.api.PayChannelService;
import com.huiminpay.transaction.api.dto.PlatformChannelDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @ClassName : AppController
 * @Author : qawine
 * @Date: 2021/3/24 20:07
 * @Description : 商户应用接口
 */
@Api(value = "商户平台-应用管理", tags = "商户平台-应用相关", description = "商户平台-应用相关")
@RestController
public class AppController {
    @Reference
    private AppService appService;

    @Reference
    IMerchantService merchantService;

    @ApiOperation("商户创建应用")
    @ApiImplicitParams({@ApiImplicitParam(name = "app", value = "应用信息", required = true, dataType = "AppDTO", paramType = "body")})
    @PostMapping(value = "/my/apps")
    public AppDTO createApp(@RequestBody AppDTO app, HttpServletRequest request) {
//        request.setAttribute("jsonToken","eyJtZXJjaGFudElkIjoxNDA2MjQzNTU1OTQwNTA3NjQ5LCJ1c2VyX25hbWUiOiJzdHJpbmciLCJtb2JpbGUiOiIxMjMxMjIyMiIsInRlbmFudElkIjoxMjM0NTZ9");
        Long merchantId = SecurityUtil.getMerchantId(merchantService);
        return appService.createApp(merchantId, app);
    }


    /**
     *  根据appId 查询应用详情
     * @author qawine
     * @param appId
     * @return com.huiminpay.merchant.api.dto.AppDTO
     * @date 2021/3/24 20:32
     */
    @ApiOperation("根据appid获取应用的详细信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "appId", value = "商户应用id", required = true, dataType = "String", paramType = "path")})
    @GetMapping(value = "/my/apps/{appId}")
    public AppDTO getApp(@PathVariable String appId) {
        return appService.getAppById(appId);
    }


}